package com.ruoyi.make.controller;

import java.util.List;
import java.io.IOException;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.make.domain.LldWlAndDw;
import com.ruoyi.make.domain.ScllMaterialRequiredRescord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.make.domain.ScllProductionMaterialRequisition;
import com.ruoyi.make.service.IScllProductionMaterialRequisitionService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 生产领料Controller
 * 
 * @author ruoyi
 * @date 2024-07-01
 */
@RestController
@RequestMapping("/formTwo")
public class ScllProductionMaterialRequisitionController extends BaseController
{
    @Resource
    private IScllProductionMaterialRequisitionService scllProductionMaterialRequisitionService;

    /**
     * 查询生产领料列表
     */
    @RequiresPermissions("scll:formTwo:list")
    @GetMapping("/list")
    public TableDataInfo list(ScllProductionMaterialRequisition scllProductionMaterialRequisition)
    {
        startPage();
        List<ScllProductionMaterialRequisition> list = scllProductionMaterialRequisitionService.selectScllProductionMaterialRequisitionList(scllProductionMaterialRequisition);
        return getDataTable(list);
    }

    /**
     * 查询生产领料单物料
     */
    @RequiresPermissions("scll:formTwo:lldList")
    @GetMapping("/lldList")
    public AjaxResult getLldList(String lldh){
        System.out.println("==============================="+lldh);
        return success(scllProductionMaterialRequisitionService.selectLldWlAndDwList(lldh));
    }


    /**
     * 查询哪些仓库有这些物料
     */
    @RequiresPermissions("scll:formTwo:getCk")
    @GetMapping("/getCk")
    public AjaxResult getCk(String wlCode){

        return success(scllProductionMaterialRequisitionService.CkByWlCode(wlCode));
    }

    /**
     * 领料
     */
    @RequiresPermissions("scll:formTwo:getLl")
    @PostMapping("/getLl")
    public AjaxResult getCk(@RequestBody List<ScllMaterialRequiredRescord> scllMaterialRequiredRescords){
        return toAjax(scllProductionMaterialRequisitionService.insertScllMaterialRequiredRescord(scllMaterialRequiredRescords));
    }


    /**
     * 审核
     */
    @RequiresPermissions("scll:formTwo:auditMaterial")
    @GetMapping("/auditMaterial")
    public AjaxResult auditMaterial(Long scllId){
        return toAjax(scllProductionMaterialRequisitionService.auditMaterialRequisition(scllId));
    }

    /**
     * 导出生产领料列表
     */
    @RequiresPermissions("scll:formTwo:export")
    @Log(title = "生产领料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScllProductionMaterialRequisition scllProductionMaterialRequisition)
    {
        List<ScllProductionMaterialRequisition> list = scllProductionMaterialRequisitionService.selectScllProductionMaterialRequisitionList(scllProductionMaterialRequisition);
        ExcelUtil<ScllProductionMaterialRequisition> util = new ExcelUtil<ScllProductionMaterialRequisition>(ScllProductionMaterialRequisition.class);
        util.exportExcel(response, list, "生产领料数据");
    }

    /**
     * 获取生产领料详细信息
     */
    @RequiresPermissions("scll:formTwo:query")
    @GetMapping(value = "/{scllId}")
    public AjaxResult getInfo(@PathVariable("scllId") Long scllId)
    {
        return success(scllProductionMaterialRequisitionService.selectScllProductionMaterialRequisitionByScllId(scllId));
    }

    /**
     * 新增生产领料
     */
    @RequiresPermissions("scll:formTwo:add")
    @Log(title = "生产领料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScllProductionMaterialRequisition scllProductionMaterialRequisition)
    {
        return toAjax(scllProductionMaterialRequisitionService.insertScllProductionMaterialRequisition(scllProductionMaterialRequisition));
    }

    /**
     * 修改生产领料
     */
    @RequiresPermissions("scll:formTwo:edit")
    @Log(title = "生产领料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScllProductionMaterialRequisition scllProductionMaterialRequisition)
    {
        return toAjax(scllProductionMaterialRequisitionService.updateScllProductionMaterialRequisition(scllProductionMaterialRequisition));
    }

    /**
     * 删除生产领料
     */
    @RequiresPermissions("scll:formTwo:remove")
    @Log(title = "生产领料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scllIds}")
    public AjaxResult remove(@PathVariable Long[] scllIds)
    {
        return toAjax(scllProductionMaterialRequisitionService.deleteScllProductionMaterialRequisitionByScllIds(scllIds));
    }
}
